﻿using System;
using System.Windows.Forms;

using DataCollectionSystem_attach.Subpage;

namespace LengthAiCalculate
{
    public partial class GetLength : Form
    {
        public GetLength()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var client = new TcpClientWrapper(textBox1.Text, int.Parse(textBox2.Text));
            client.CStatus_NO += Client_CStatus_NO;
            client.CStatus_OK += Client_CStatus_OK;
            while (true)
            {
                try
                {
                    client.Connect();
                    if (client._isConnected)
                    {
                        break;
                    }
                }
                catch
                {
                }
            }
            client.MessageReceived += Client_MessageReceived;
        }

        private void Client_MessageReceived(string message)
        {
            Invoke(new Action(() =>
            {
                label1.Text = message;
                label1.Refresh();
            }));
        }

        private void Client_CStatus_OK()
        {
        }

        private void Client_CStatus_NO()
        {
        }
    }
}